package org.simple.framework.service.flow.executor;

import org.simple.framework.service.step.StepService;
import org.simple.framework.service.support.StepExecutionContextBuilder;
import org.springframework.beans.factory.annotation.Autowired;

import com.simple.framework.infrastructure.pojo.FlowExecutionContext;
import com.simple.framework.infrastructure.pojo.FlowStep;
import com.simple.framework.infrastructure.pojo.Step;
import com.simple.framework.infrastructure.pojo.StepExecutionContext;
import com.simple.framework.infrastructure.pojo.StepTask;

/**
 * 简单的流程执行器
 * 
 * @author wujiangpo
 *
 */
public class SimpleFlowExecutor extends AbstractFlowExecutor {

	@Autowired
	private StepService stepService;

	@Autowired
	private StepExecutionContextBuilder stepExecutionContextBuilder;

	@Override
	protected void subExec(FlowExecutionContext context) {

		for (Object object : context.getFlow().getSteps()) {

			if (object instanceof Step) {

			} else if (object instanceof FlowStep) {

			} else {
				throw new RuntimeException("");
			}

			// 获取步骤实例
			//StepTask stepTask = stepService.getStepBean(step.getStepBeanName());

			// TODO 构建步骤执行上下文
			StepExecutionContext stepExecutionContext = stepExecutionContextBuilder.build(context);

			super.beforFlowStart(context);

			try {
				//stepTask.exec(stepExecutionContext);
			} catch (Exception e) {
				super.afterFlowExecException(context);
			}

			super.afterFlowEnd(context);
		}

	}

}
